package typistcal.commandlogic;
import static org.junit.Assert.*;

import org.junit.Test;

import typistcal.exception.WrongTimeFormatException;

//@author A0105620X
public class CommandDecodeTest {

	@Test
	public void test() {
		try {
			// multiple inputs test
			Command testCommand;
			// test add command

			// floating task

			testCommand = new Command("add some floating task");
			assertEquals("add to-do task", "some floating task Incomplete",
					testCommand.event.toString());

			testCommand = new Command("..a prepare gift for my friend");
			assertEquals("add w/o keyword", "prepare gift for my friend Incomplete",
					testCommand.event.toString());

			testCommand = new Command("travel from a to b");
			assertEquals("add w/o keyword", "travel from a to b Incomplete",
					testCommand.event.toString());

			testCommand = new Command("watch movie \"do sth by monday\"");
			assertEquals("quotes", "watch movie \"do sth by monday\" Incomplete",
					testCommand.event.toString());

			
			// tasks with deadline
			testCommand = new Command("submit v0.5 by 9pm on 4.14");
			assertEquals("label by time",
					"submit v0.5 by 14 April 2014 21:00 Incomplete",
					testCommand.event.toString());

			testCommand = new Command(
					"upload dev guide deadline 14 apr 2015 at 10");
			assertEquals("label deadline-date", "14 April 2015",
					testCommand.event.endDate);
			assertEquals("label deadline-time", "10:00",
					testCommand.event.endTime);
			assertEquals("label deadline-label", "upload dev guide",
					testCommand.event.label);

			testCommand = new Command("tmr  complete dev guide");
			assertEquals("time label-date", TimeUtility.parseDate("tmr"),
					testCommand.event.endDate);
			assertEquals("time label-time", "23:59", testCommand.event.endTime);
			assertEquals("label deadline-label", "complete dev guide",
					testCommand.event.label);

			testCommand = new Command("finish ma3111 hw tonight before 11");
			assertEquals("seperate deadline-date", TimeUtility.getToday(),
					testCommand.event.endDate);
			assertEquals("seperate deadline-time", "11:00",
					testCommand.event.endTime);

			// tasks with only start time
			testCommand = new Command("start to prepare  finals today");
			assertEquals("start from today", TimeUtility.getDateAndTime(),
					testCommand.event.startDate + testCommand.event.startTime);
			assertEquals("label", "start to prepare finals",
					testCommand.event.label);

			testCommand = new Command("tmr project meeting at 9 with jane");
			assertEquals("date", TimeUtility.parseDate("tmr"),
					testCommand.event.startDate);
			assertEquals("time", "9:00", testCommand.event.startTime);
			assertEquals("label", "project meeting with jane",
					testCommand.event.label);

			testCommand = new Command("exercise this tues with jane");
			assertEquals("date", TimeUtility.parseDate("this tues"),
					testCommand.event.startDate);
			assertEquals("time", "00:00", testCommand.event.startTime);
			assertEquals("label", "exercise with jane", testCommand.event.label);

			testCommand = new Command("exercise this tues with jane from 12");
			assertEquals("date", TimeUtility.parseDate("this tues"),
					testCommand.event.startDate);
			assertEquals("time", "12:00", testCommand.event.startTime);
			assertEquals("label", "exercise with jane", testCommand.event.label);

			// tasks with duration
			testCommand = new Command(
					"exercise this tues with jane for 2 hrs from 12");
			assertEquals("date", TimeUtility.parseDate("this tues"),
					testCommand.event.startDate);
			assertEquals("time", "12:00", testCommand.event.startTime);
			assertEquals("time", "14:00", testCommand.event.endTime);
			assertEquals("label", "exercise with jane", testCommand.event.label);

			testCommand = new Command("study for 2 weeks");
			assertEquals("no starting", TimeUtility.getDateAndTime(),
					testCommand.event.startDate + testCommand.event.startTime);
			assertEquals("no starting", TimeUtility.getEndTime(
					testCommand.event.startDate, testCommand.event.startTime,
					"2 weeks"), testCommand.event.endDate + ","
					+ testCommand.event.endTime);
			//assertEquals("label", "study", testCommand.event.label);

			testCommand = new Command(
					"tonight project meeting at 11pm with jane for 2 hrs");
			assertEquals("date", TimeUtility.parseDate("tonight"),
					testCommand.event.startDate);
			assertEquals("time", "23:00", testCommand.event.startTime);
			assertEquals("date", TimeUtility.parseDate("tmr"),
					testCommand.event.endDate);
			assertEquals("time", "01:00", testCommand.event.endTime);
			assertEquals("label", "project meeting with jane",
					testCommand.event.label);

			// tasks with both starting and ending time
			testCommand = new Command("study from 9 18 apr to 10pm with jane");
			assertEquals(
					"no end date specified",
					"study with jane from 18 April 2014 9:00 to 18 April 2014 22:00 Incomplete",
					testCommand.event.toString());
			
			testCommand = new Command("study from 9 to 10pm 10.1 with jane");
			assertEquals(
					"no start date specified",
					"study with jane from 1 October 2014 9:00 to 1 October 2014 22:00 Incomplete",
					testCommand.event.toString());
			
			testCommand = new Command("study from 9 to 10pm 10.1 with jane for a-b");
			assertEquals(
					"no start date specified",
					"study with jane for a-b from 1 October 2014 9:00 to 1 October 2014 22:00 Incomplete",
					testCommand.event.toString());
			
			testCommand = new Command("study from 9 today to 10pm 10.1 with jane");
			assertEquals("no start date specified to be today",
					TimeUtility.getToday(),
					testCommand.event.startDate);
			assertEquals("no start date specified to be today",
					"1 October 2014",
					testCommand.event.endDate);
			
			testCommand = new Command("study at 9 -10pm on May 7 with jane");
			assertEquals(
					"dash as connection",
					"study with jane from 7 May 2014 9:00 to 7 May 2014 22:00 Incomplete",
					testCommand.event.toString());
			
			testCommand = new Command("vacation 2 may-aug 10");
			assertEquals(
					"dash as connection",
					"vacation from 2 May 2014 00:00 to 10 August 2014 23:59 Incomplete",
					testCommand.event.toString());
			
			testCommand = new Command("study from 8 apr 2014 to 19 apr");
			assertEquals(
					"bug found",
					"study from 8 April 2014 00:00 to 19 April 2014 23:59 Incomplete",
					testCommand.event.toString());

			// test delete command
			testCommand = new Command("delete some label word");
			assertEquals("delete keyword", "some label word",
					testCommand.event.eventKeyword);

			testCommand = new Command("delete 11 12 13");
			assertEquals("delete keyword", "11 12 13",
					testCommand.event.eventKeyword);
			assertEquals("delete line number", 12,
					testCommand.event.lineNumber[1]);

			// test update command
			testCommand = new Command("upd task xxx label yyy");
			assertEquals("eventKeyword", "task xxx",
					testCommand.event.eventKeyword);
			assertEquals("fieldKeyword", "label",
					testCommand.event.fieldKeyword);
			assertEquals("toKeyword", "yyy", testCommand.event.toKeyword);

			testCommand = new Command("update 11 label word");
			assertEquals("update line number", 11,
					testCommand.event.lineNumber[0]);
			
			testCommand = new Command("upd task xxx to yyy");
			assertEquals("eventKeyword", "task xxx",
					testCommand.event.eventKeyword);
			assertEquals("fieldKeyword", "label",
					testCommand.event.fieldKeyword);
			assertEquals("toKeyword", "yyy", testCommand.event.toKeyword);
			
			testCommand = new Command("update abcdefg done");
			assertEquals("update line number", "abcdefg",
					testCommand.event.eventKeyword);
			assertEquals("update line number", "status",
					testCommand.event.fieldKeyword);
			assertEquals("update line number", "Completed",
					testCommand.event.toKeyword);

			// test show
			testCommand = new Command("show some label word");
			assertEquals("event keyword", "some label word",
					testCommand.event.eventKeyword);

			testCommand = new Command("show today");
			assertEquals("event keyword without quotes",
					TimeUtility.parseDate("today"),
					testCommand.event.eventKeyword);

			testCommand = new Command("show \"today\"");
			assertEquals("event keyword with quotes", "today",
					testCommand.event.eventKeyword);

			testCommand = new Command("show 11");
			assertEquals("show line number", 11,
					testCommand.event.lineNumber[0]);

		} catch (WrongTimeFormatException e) {
		}
	}

	
}
